package br.com.struts.controller.cliente.negocio;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import br.com.struts.model.Cliente;

@Service
public class ClienteService {

	@Autowired
	private ClienteBO clienteBO;

	@Transactional(readOnly = true)
	public Collection<Cliente> listarTodos() {
		Collection<Cliente> clientes = null;
		try {
			clientes = clienteBO.listarTodos();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return clientes;
	}

	@Transactional(readOnly = true)
	public Cliente buscarPorId(Long id) {
		Cliente cliente = null;
		try {
			cliente = clienteBO.buscarPorId(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return cliente;
	}

	@Transactional
	public void salvar(Cliente cliente) {
		try {
			clienteBO.salvar(cliente);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Transactional
	public void atualizar(Cliente cliente) {
		try {
			clienteBO.atualizar(cliente);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Transactional
	public void deletar(Cliente cliente) {
		try {
			clienteBO.deletar(cliente);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
